<?php

class Jobs
{
	
	function add_post($companyName, $jobTitle, $address, $city, $state, $zip, $oDate, $cDate, $wage, $time, $dur, $shift, $trans, $expRequired, $expLevel, $jobDesc, $reqQual, $howApply, $otherNotes)
	{	
		$oDate = date('Y-m-d', strtotime($oDate));
		$cDate = date('Y-m-d', strtotime($cDate));
		
		$conn = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD) or die('An error has occured: Could not connect to the MySQL database.');
		mysql_select_db(DB_NAME) or die("An error has occured:  Could not connect to the table.");
		
		$sql = 'insert into wms_job ';
		$sql .= '(fk_employer_id, job_title, job_st_address, job_city, job_state, job_zip, opening_date, closing_date, starting_wage, full_part, perm_temp, shift, transportation, exp_level, job_description, requirements, how_to_apply, other_notes, modified, is_active) ';
		$sql .= "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %s);";
		
		$sql = sprintf($sql
			,mysql_real_escape_string($companyName)
			,mysql_real_escape_string($jobTitle)
			,mysql_real_escape_string($address)
			,mysql_real_escape_string($city)
			,mysql_real_escape_string($state)
			,mysql_real_escape_string($zip)
			,mysql_real_escape_string($oDate)
			,mysql_real_escape_string($cDate)
			,mysql_real_escape_string($wage)
			,mysql_real_escape_string($time)
			,mysql_real_escape_string($dur)
			,mysql_real_escape_string($shift)
			,mysql_real_escape_string($trans)
			,mysql_real_escape_string($expLevel)
			,mysql_real_escape_string($jobDesc)
			,mysql_real_escape_string($reqQual)
			,mysql_real_escape_string($howApply)
			,mysql_real_escape_string($otherNotes)
			,mysql_real_escape_string(date('Y-m-d H:i:s'))
			,true);
		
		$result = mysql_query($sql);
	
		if(!$result) die("An error has occured: " . mysql_error());
	
		$identity = mysql_query('select @@identity;');
		$identity = mysql_fetch_assoc($identity);
		$identity = $identity['@@identity'];
		
		foreach($expRequired as $exp)
		{
			$sql = 'insert into wms_jobExperience (jobID, experienceID) values(%s, %s);';
			$sql = sprintf($sql, mysql_real_escape_string($identity), mysql_real_escape_string($exp));
			
			$result = mysql_query($sql);
			if(!$result) die("An error has occured: " . mysql_error());
		}
		
		mysql_close($conn);	
	}
	
}

?>